package com.x.erp.controller;


import com.x.erp.model.vo.RegionVO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.x.erp.model.Region;
import com.x.erp.rpc.RegionRpcService;
import com.x.framework.controller.BaseController;
import com.x.framework.controller.ResultCode;
import com.x.framework.controller.ResultModel;

/**
 * 车场区域信息
 */
@RestController
public class RegionController extends BaseController{

	@Reference
	private RegionRpcService regionRpcService;//车场区域服务

	/**
	 * 查询车场区域信息
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/getRegionList", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultModel getRegionList(Region region, RegionVO regionVO) {
		region.setRegionVO(regionVO);
		return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功", regionRpcService.selectRegionList(region));
	}

	/**
	 * 查询车场区域信息
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/selectRegionNum", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultModel selectRegionNum(Region region, RegionVO regionVO) {
		region.setRegionVO(regionVO);
		return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功", regionRpcService.selectRegionNum(region));
	}

	/**
	 * 插入更新店铺
	 * @param shop
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/insertOrUpdateRegion", method = {RequestMethod.GET, RequestMethod.POST})
	public ResultModel insertOrUpdateShop(Region region) {
		if(this.isNotNull(region.getRegionId())){
			regionRpcService.updateRegion(region);
			return new ResultModel(ResultCode.RESULT_SUCCESS, "修改成功！");
		}else{
			regionRpcService.insertRegion(region);
			return new ResultModel(ResultCode.RESULT_SUCCESS, "新增成功！");
		}
	}

}
